<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
* {
box-sizing: border-box;
}

.box {
width: 560px;
height: 400px;
background-color: pink;
}

img {
width: 100%;
height: 320px;
display: block;
}

.bottom {
height: 80px;
background-color: green;
padding: 10px 10px 0 10px;
position: relative;
}

.zy{
    position: absolute;
    top: 10px;
    right: 10px;
}
.left,.right{
    text-align: center;
    display: inline-block;
    background-color: rgba(173, 170, 170, 0.329);
    color: #d7d3d3c4;
    margin-right: 10px;
    width: 20px;
    height: 20px;
    line-height: 20px;
    padding-bottom: 10px;
    cursor: pointer;
}

.bottom p {
margin: 0;
color: white;
margin-bottom: 10px;
}

.bottom-ul {
width: 150px;
display: flex;
list-style: none;
margin: 0;
padding: 0;
justify-content: space-between;
align-items: center;
}

.bottom-ul li {
width: 8px;
height: 8px;
margin: 4px;
border-radius: 50%;
background: #fff;
opacity: 0.4;
cursor: pointer;
}

li.lihover {
width: 12px;
height: 12px;
opacity: 1;
}
</style>
</head>

<body>
<div class="box">
    <img src="../渲染列表图片/images/course01.png" alt="">
    <div class="bottom">
        <p>啊啊啊啊啊啊啊啊啊啊啊啊啊啊</p >
            <div class="zy">
                <span class="left"><</span>
                <span class="right">></span>
            </div>
        <ul class="bottom-ul">
            <li class="light"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
</div>
<script>
    const box=document.querySelector('.box')
    const left=document.querySelector('.left')
    const right=document.querySelector('.right')
    
const sliderData = [
{ url: '../渲染列表图片/images/course01.png', title: '对人类来说会不会太超前了？', color: 'rgb(100, 67, 68)' },
{ url: '../渲染列表图片/images/course02.png', title: '开启剑与雪的黑暗传说！', color: 'rgb(43, 35, 26)' },
{ url: '../渲染列表图片/images/course03.png', title: '真正的jo厨出现了！', color: 'rgb(36, 31, 33)' },
{ url: '../渲染列表图片/images/course04.png', title: '快来分享你的寒假日常吧~', color: 'rgb(139, 98, 66)' },
{ url: '../渲染列表图片/images/course05.png', title: '李玉刚：让世界通过B站看到东方大国文化', color: 'rgb(67, 90, 92)' },
{ url: '../渲染列表图片/images/course06.png', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },
{ url: '../渲染列表图片/images/course07.png', title: '一站式解决你的电脑配置问题！！！', color: 'rgb(53, 29, 25)' },
{ url: '../渲染列表图片/images/course08.png', title: '谁不想和小猫咪贴贴呢！', color: 'rgb(99, 72, 114)' },
]

//1。获取元素
const img = document.querySelector('img')
//2.更换文本
const p = document.querySelector('p')
//3.背景颜色
const bc = document.querySelector('.bottom')
//4.小圆点

let i=0
function bofang(){
    mytime=setInterval(function(){
        i++
        if(i>=sliderData.length){
        i=0
    }
    img.src=sliderData[i].url
    p.innerHTML=sliderData[i].title
    bc.style.backgroundColor=sliderData[i].color

    //删除小圆点
    const scli=document.querySelector('ul .light')
    scli.classList.remove('light')
    scli.classList.remove('lihover')

    const li = document.querySelector(`li:nth-child(${i+1})`)
    li.classList.add('light')
    li.classList.add('lihover')
    },500)
}


box.addEventListener('mouseover',function(){//鼠标型-移入
            clearInterval(mytime)
        })

left.addEventListener('click',function(){//鼠标型-点击-左边
    if(i<=0){
        i=sliderData.length
    }
    i--
    img.src=sliderData[i].url
    p.innerHTML=sliderData[i].title
    bc.style.backgroundColor=sliderData[i].color

    const scli=document.querySelector('ul .light')
    scli.classList.remove('light')
    scli.classList.remove('lihover')

    const li = document.querySelector(`li:nth-child(${i+1})`)
    li.classList.add('light')
    li.classList.add('lihover')
})

right.addEventListener('click',function(){//鼠标型-点击-右边
    if(i>=sliderData.length){
        i=0
    }
    i++
    img.src=sliderData[i].url
    p.innerHTML=sliderData[i].title
    bc.style.backgroundColor=sliderData[i].color
    
    const scli=document.querySelector('ul .light')
    scli.classList.remove('light')
    scli.classList.remove('lihover')

    const li = document.querySelector(`li:nth-child(${i+1})`)
    li.classList.add('light')
    li.classList.add('lihover')
})

box.addEventListener('mouseout',bofang)//鼠标型-移出
bofang()
</script>
</body>

</html>